//
//  SettingMoneyViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/27.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "SettingMoneyViewController.h"
#import "JTCSM.h"
#import "GetInfoClass.h"
#import "JiaoyiTypeViewController.h"
#import "My_KeyBoardView.h"
#import "MyInfoView.h"

static CGFloat space = 20;

@interface SettingMoneyViewController ()<UITextFieldDelegate,JiaoyiTypeViewControllerDelegate,My_KeyBoardDelegate>
{
    UIScrollView *backScrollV;
    UILabel *mylabel;
    NSString *phone;
    NSString *type;
    CGFloat viewHeight ;
    CGFloat labelheight ;
    
}
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UIImageView *statusImageView;
@property (nonatomic,strong) UITextField *textfield;
@property (nonatomic,strong) My_KeyBoardView *my_keyboard;
@property (nonatomic,strong) UIView *secondView;
@property (nonatomic,strong) MyInfoView *infoView;


@end

@implementation SettingMoneyViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    type = @"";
    backScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, KagainChangeHeight, KCONTROLLERWith, KCONTROLLERHeight-50)];
    backScrollV.backgroundColor = [UIColor whiteColor];
    backScrollV.userInteractionEnabled = YES;
    backScrollV.bounces = NO;
    backScrollV.showsVerticalScrollIndicator = NO;
    [self.view addSubview:backScrollV];
    
   viewHeight = 60*[JTCSMSingle shareSingle].adaptationNumber;
    labelheight = 50*[JTCSMSingle shareSingle].adaptationNumber;
    
    [self layoutOtherView];
    [self layoutHeaderView];
    
    [self keyBoardTypeAction];
 }
- (void)keyBoardTypeAction {
  
    self.my_keyboard = [[My_KeyBoardView alloc] initWithNumber:@1];
    
    self.my_keyboard.delegate = self;
    [self.view addSubview:self.my_keyboard];
}
#pragma mark My_KeyBoardViewDelegate
- (void)numberKeyBoard:(NSInteger)number
{
    NSString *str = self.textfield.text;
    if ([self.textfield.text rangeOfString:@"."].location == NSNotFound) {
        if ([str isEqualToString:@""] || str==nil) {
            if (number == 0) {
                self.textfield.text = [NSString stringWithFormat:@"%@%ld.",str,(long)number];
            }else{
                self.textfield.text = [NSString stringWithFormat:@"%@%ld",str,(long)number];
            }
        }else{
            self.textfield.text = [NSString stringWithFormat:@"%@%ld",str,(long)number];
        }
    }else{
        NSRange range = [str rangeOfString:@"."];
        if (str.length >=range.location+3) {
            return;
        }else{
            self.textfield.text = [NSString stringWithFormat:@"%@%ld",str,(long)number];
        }
        
    }
    
    
   
}
- (void)doubleNumberKeyBoard{
    NSString *str = self.textfield.text;
    
    if ([self.textfield.text rangeOfString:@"."].location == NSNotFound) {
        if ([str isEqualToString:@""] || str==nil) {
            
            return;
        }else{
            self.textfield.text = [NSString stringWithFormat:@"%@00",str];
        }
    }else{
        NSRange range = [str rangeOfString:@"."];
        self.textfield.text = [NSString stringWithFormat:@"%@00",str];
        if (self.textfield.text.length >range.location+3) {
            self.textfield.text = [self.textfield.text stringByReplacingCharactersInRange:NSMakeRange(range.location+3, self.textfield.text.length-(range.location+3)) withString:@""];
        }
    }
}
- (void)cancelKeyBoard{

    NSMutableString *muStr = [[NSMutableString alloc] initWithString:self.textfield.text];
    if (muStr.length <= 0) {
            return;
        }
    [muStr deleteCharactersInRange:NSMakeRange([muStr length] - 1, 1)];
    self.textfield.text = muStr;
}

- (void)removeAllData{
    self.textfield.text = @"";
}
- (void)finishKeyBoard{
    
    [self gotoMainV];
}


 #pragma 输入点
-(void)periodKeyBoard{
    if ([self.textfield.text isEqualToString:@""]) {
        self.textfield.text=@"0.";
        return;
   }
   
    //判断当前时候存在一个点
    if ([self.textfield.text rangeOfString:@"."].location == NSNotFound) {
            //输入中没有点
            NSMutableString  *mutableString=[[NSMutableString alloc]initWithFormat:@"%@%@",self.textfield.text,@"."];
            self.textfield.text=mutableString;
        }
}


- (void)layoutOtherView{
    
    CGFloat changeHeight = 18*[JTCSMSingle shareSingle].adaptationNumber;
    
    CGFloat LabelHeight = 120*[JTCSMSingle shareSingle].adaptationNumber;
    NSString *title = @"¥";
    CGFloat font = 36*[JTCSMSingle shareSingle].adaptationNumber;
    CGRect rect = [df labelHeightWithContent:title height:LabelHeight font:font];
    
    UILabel *label = [UILabel initWithFrame:CGRectMake(space, 4+changeHeight+(LabelHeight-rect.size.height)/2, rect.size.width, rect.size.height) text:title font:font textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
    [backScrollV addSubview:label];
    
    
    self.textfield = [UITextField initWithframe:CGRectMake(KVIEW_X(label)+5, 0+changeHeight+5, KCONTROLLERWith-KVIEW_X(label)-space-5, LabelHeight) backgrandColor:nil placeholder:@"输入金额" textAlignment:NSTextAlignmentLeft font:font texcolor:RGBACOLOR(52, 52, 52, 1)];
    self.textfield.enabled = NO;
    [backScrollV addSubview:self.textfield];
    
    [df lineViewWithHeightofTop:KVIEW_Y(self.textfield)+10 superView:backScrollV spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:2];
    
    
}


- (void)layoutHeaderView{
   
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(_textfield)+10, KCONTROLLERWith, viewHeight)];
    backview.userInteractionEnabled = YES;
    [backScrollV addSubview:backview];
    
    self.statusImageView.userInteractionEnabled = YES;
     CGFloat labelfontsize = (KSCREENWidth ==320?14:(KSCREENWidth==375?15:16));
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(space, 0, 2003, viewHeight) text:@"交易方式：请选择" font:labelfontsize textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
    [backview addSubview:titleLabel];
   titleLabel.userInteractionEnabled = YES;
    
    CGRect rect1 = [df labelHeightWithContent:@"更换" width:1000 font:15];
    UILabel *morelabel = [UILabel initWithFrame:CGRectMake(KCONTROLLERWith-space-rect1.size.width, (viewHeight-rect1.size.height-2)/2, rect1.size.width, rect1.size.height+2) text:@"更换" font:15 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [backview addSubview:morelabel];
    titleLabel.userInteractionEnabled = YES;
    [df newlineViewWithHeightofTop:rect1.size.height+2 superView:morelabel spacing:0 color:[df colorWithHexString:@"333333" alpha:1] lineHeight:1];
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotobankList) andaddView:backview];
    
    backScrollV.frame = CGRectMake(0, 0, KCONTROLLERWith, KVIEW_Y(_textfield)+10+viewHeight);
    
    _secondView = [[UIView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(backScrollV)+10, (KCONTROLLERWith-0), labelheight)];
    _secondView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_secondView];
    [df layerWithView:_secondView radius:5 width:0 color:nil];
    CGFloat headerImagesize = 15;
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, (labelheight-headerImagesize)/2, headerImagesize, headerImagesize)];
    imageView.image = [UIImage imageNamed:@"设置金额_注.png"];
    [_secondView addSubview:imageView];
    CGFloat fontsize = (KSCREENWidth ==320?12:(KSCREENWidth==375?14:15));
    UILabel *label = [UILabel initWithFrame:CGRectMake(KVIEW_X(imageView)+10 , 0, KCONTROLLERWith, labelheight) text:@"交易金额不低于1元，大额交易建议使用快捷支付" font:fontsize textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
    [_secondView addSubview:label];
    
}

- (void)gotoMainV{
    

//    LoadData *request = [[LoadData alloc]init];
//    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"UserReceive/create") withDict:@{@"token":KTokenString,@"encrypt":self.encrypt,@"type":type,@"total_price":self.textfield.text} superView:nil isAddtag:YES Block:^(id result) {
//
//        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
//
//        if ([isreturn isEqualToString:@"1"]) {
//
//            NSDictionary *dict = KResultOfKey(@"data");
//
//
//            [self.delegate getMoney:[dict objectForKey:@"total_price"] erweima:[dict objectForKey:@"qrcode"] backImage:[dict objectForKey:@"poster"]];
            [self gotBack];
//
//        }
//    }];

    
}


- (void)gotobankList{
    JiaoyiTypeViewController *vc = [[JiaoyiTypeViewController alloc]init];
    vc.nameTitle = @"交易方式";
    vc.delegate = self;
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark 交易方式代理方法
- (void)getTitle:(NSString *)title typeid:(NSString *)mytypeid{
    self.nameLabel.text = title;
    type = mytypeid;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
